package com.lcm.learn.lcmcode.lock;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicStampedReference;

/**
 * @description:
 * @author: lcm
 * @create: 2019-12-19 14:25
 **/

public class AtomicTest {

    private static volatile int value;

    public static void main(String[] args){
        AtomicInteger atomicInteger=new AtomicInteger();
        atomicInteger.getAndAdd(1);

        AtomicInteger atomicInteger2=new AtomicInteger();

        System.out.println(value);


        AtomicStampedReference atomicStampedReference=new AtomicStampedReference(1,1);

        System.out.println("stamp:"+atomicStampedReference.getStamp()+",ref:"+atomicStampedReference.getReference());
        System.out.println(atomicStampedReference.compareAndSet(atomicStampedReference.getReference(),100,1,2));
        System.out.println("stamp:"+atomicStampedReference.getStamp()+",ref:"+atomicStampedReference.getReference());
        System.out.println(atomicStampedReference.compareAndSet(atomicStampedReference.getReference(),101,1,3));
        System.out.println("stamp:"+atomicStampedReference.getStamp()+",ref:"+atomicStampedReference.getReference());
        System.out.println(atomicStampedReference.compareAndSet(1,102,atomicStampedReference.getStamp(),4));
    }

}
